package com.zoroki.student_score_system.controller;

import com.zoroki.student_score_system.domain.Semester;
import com.zoroki.student_score_system.domain.UserClass;
import com.zoroki.student_score_system.service.SemesterService;
import com.zoroki.student_score_system.service.UserClassService;
import com.zoroki.student_score_system.utils.Msg;
import com.zoroki.student_score_system.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/userClass")
public class UserClassController {
    @Autowired
    UserClassService userClassService;


    @GetMapping("/getUserClassList")
    public @ResponseBody Result<List<UserClass>> getUserClassList() {
        return new Result<List<UserClass>>(0,userClassService.getUserClassList(), Msg.SUCCESS);
    }

    @GetMapping("/getUserClassByUserId")
    public @ResponseBody Result<UserClass> getUserClassByUserId(int userId) {
        return new Result<UserClass>(0,userClassService.getUserClassByUserId(userId), Msg.SUCCESS);
    }

    @GetMapping("/getUserClassByClassId")
    public @ResponseBody Result<UserClass> getUserClassByClassId(int classId) {
        return new Result<UserClass>(0,userClassService.getUserClassByClassId(classId), Msg.SUCCESS);
    }

    @PostMapping("/addUserClass")
    public @ResponseBody Result<Boolean> addUserClass(int userId ,int classId) {
        System.out.println(userId+" : "+classId);
        UserClass userClass = new UserClass();
        userClass.setUserId(userId);
        userClass.setClassId(classId);

        return new Result<Boolean>(0,userClassService.addUserClass(userClass), Msg.SUCCESS);
    }
}
